<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Helper_Format {

    public static function format_date($date, $input_format = null, $format = null) {
        if ($input_format === null) {
            $input_format = 'Y-m-d';
        }
        if ($format === null) {
            $format = "m/d/Y";
        }
        if (empty($date)) {
            return "";
        }

        $a_date = explode(" ", $date);
        if (count($a_date) >= 2) {
            $date = $a_date[0];
        }
        try {
            $my_date_time = DateTime::createFromFormat($input_format, $date);

            if ($my_date_time == null) {
                return "";
            }
            $new_date_string = $my_date_time->format($format);
            return $new_date_string;
        } catch (Exception $e) {
            return "";
        }
    }

}

?>
